package com.txd.mofa.fenlei.fgt;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.kongzue.baseframework.interfaces.Layout;
import com.kongzue.baseframework.util.JumpParameter;
import com.kongzue.baseframework.util.OnJumpResponseListener;
import com.kongzue.baseokhttp.HttpRequest;
import com.kongzue.baseokhttp.listener.ResponseListener;
import com.kongzue.baseokhttp.util.Parameter;
import com.ninetaildemonfox.zdl.ninetails.map.JSONUtils;
import com.txd.mofa.R;
import com.txd.mofa.adapter.FenleiAdapter;
import com.txd.mofa.adapter.FragmentAdp;
import com.txd.mofa.base.BaseFgt;
import com.txd.mofa.bean.FenleiBean;
import com.txd.mofa.fenlei.aty.FenleiListAty;
import com.txd.mofa.net.NetUtils;
import com.txd.mofa.view.HXLinePagerIndicator;
import com.txd.mofa.view.ScaleTransitionPagerTitleView;
import com.txd.mofa.xiangce.models.puzzle.Line;

import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Layout(R.layout.fgt_fenlei)
public class FenleiFgt extends BaseFgt {

    private RecyclerView recy;
    private FenleiAdapter fenleiAdapter;
    private String s;
    private ArrayList<Map<String, String>> child_one;

    public static FenleiFgt newInstance(String s) {

        Bundle args = new Bundle();
        args.putString("s", s);
        FenleiFgt fragment = new FenleiFgt();
        fragment.setArguments(args);
        return fragment;
    }

    @SuppressLint("WrongConstant")
    @Override
    public void initViews() {
        super.initViews();

        recy = findViewById(R.id.recy);

        s = FenleiFgt.this.getArguments().getString("s");

        LinearLayoutManager gridLayoutManager = new LinearLayoutManager(me);
        gridLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

        recy.setLayoutManager(gridLayoutManager);

        fenleiAdapter = new FenleiAdapter(R.layout.item_fenlei);
        recy.setAdapter(fenleiAdapter);


        http();
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    public void onLazyLoad() {

    }

    private String grand_id = "";

    private void http() {
        HttpRequest.POST(me, categoryList, new Parameter(), new ResponseListener() {
            @Override
            public void onResponse(String response, Exception error) {
                if (error == null) {
                    Map<String, String> map = JSONUtils.parseKeyAndValueToMap(response);
                    if (map.get("code").equals("1")) {
                        ArrayList<Map<String, String>> data = JSONUtils.parseKeyAndValueToMapList(map.get("data"));


                        Map<String, String> map1 = data.get(Integer.parseInt(s));
                        grand_id = map1.get("grand_id");
                        child_one = JSONUtils.parseKeyAndValueToMapList(map1.get("child_one"));
                        if (child_one.size() == 0){
                            fenleiAdapter.setEmptyView(getView);
                        }
                        fenleiAdapter.setNewData(child_one);

                    }

                } else {
                    toast("网络异常");
                }
            }
        });
    }

    @Override
    public void setEvents() {

        fenleiAdapter.setOnclick(new FenleiAdapter.Onclick() {
            @Override
            public void click(int poss, int pos) {

                Map<String, String> map = child_one.get(poss);
                ArrayList<Map<String, String>> child_two = JSONUtils.parseKeyAndValueToMapList(map.get("child_two"));
                jump(FenleiListAty.class, new JumpParameter()
                        .put("grand_id", grand_id)
                        .put("father_id", child_one.get(poss).get("father_id"))
                        .put("son_id", child_two.get(pos).get("son_id"))
                        .put("name", child_two.get(pos).get("title")), new OnJumpResponseListener() {
                    @Override
                    public void OnResponse(JumpParameter jumpParameter) {
                        Log.e("==========",")))))))))))))");
                        EventBus.getDefault().post(new FenleiBean(s));

                    }
                });

            }
        });


    }
}
